import com.engine.common.util.ServiceUtil;
import com.weaverboot.tools.logTools.LogTools;
import com.weaverboot.weaResultMsg.impl.formResult.impl.WeaFormSendComponentResultMsg;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

public class ConnegResource {
    /**
     * 获取表单的demo
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/getFormDemo")
    @Produces({MediaType.TEXT_PLAIN})
    public String getFormDemo(@Context HttpServletRequest request, @Context HttpServletResponse response){
        WeaFormSendComponentResultMsg weaFormResultMsg; //声明想要发送的消息体类
        try {
            //获取当前用户
            User user = HrmUserVarify.getUser(request, response);
            //获取业务层返回的消息体
            weaFormResultMsg = demoService.getForm();
            //检查用户是否有权限
            weaFormResultMsg.checkRight(user);
            //设置返回状态正确
            weaFormResultMsg.setApi_status(true);
        } catch (Exception e) {
            LogTools.writeLog("发生错误，原因为:" + e.getMessage());
            //建立一个返回消息体类
            weaFormResultMsg = new WeaFormSendComponentResultMsg();
            //设置返回状态为错误
            weaFormResultMsg.setApi_status(false);
            //设置错误信息
            weaFormResultMsg.setApi_errormsg(e.getMessage());
        }

        ServiceUtil.getService()
        //序列化消息体类，返回json报文
        return weaFormResultMsg.resultToSerialization();
    }
}
